package org.agile4j.algorithm.recursion;

import java.util.ArrayList;

/**
 * RecursionDemo01
 *
 * @author hanyx
 * @date 2019/01/04
 */
public class RecursionDemo01 {

    public static int[] stepArray = {1,2};
    public static int count = 0;

    /**
     * @param ladder 指定台阶数
     * @param result 结果
     */
    public static void getStep(int ladder, ArrayList<Integer> result) {
        // 正好到达指定台阶
        if (ladder == 0) {
            count ++;
            System.out.println(result);
            return;
        }
        // 超过指定台阶
        else if (ladder < 0) {
            return;
        } else {
            for (int step : stepArray) {
                ArrayList<Integer> subResult = (ArrayList<Integer>) result.clone();
                subResult.add(step);
                getStep(ladder - step,subResult);
            }
        }
    }

    public static int getStep(int ladder){
        if (ladder == 1) {
            return 1;
        }
        if (ladder == 2) {
            return 2;
        }
        return getStep(ladder - 1) + getStep(ladder - 2);
    }

    public static void main(String[] args) {
        int ladder = 7;
        getStep(ladder, new ArrayList<Integer>());
        System.out.println(count);
        System.out.println(getStep(ladder));
    }
}
